/* Copyright (C) 2011. ChengDu Unicon system, All Rights Reserved */

/*""FILE COMMENT""******************************* Technical reference data ****
* File Name	: sparkControl.asm
* Version 	: 1.00
* Device 	: SH72543
* Tool Chain 	: 
* H/W Platform	: 
* Description 	: 
******************************************************************************/

/******************************************************************************
* History 	: 
*		: 
*FILE COMMENT END*********************************************************/
;Include OS_CTX_SAVE and OS_CTX_RESTORE macros
        #include    "os_cpu_a.inc"
        
        
        PUBLIC     _SparkTimer1ISR
        PUBLIC     _SparkTimer2ISR
        PUBLIC     _SparkTimer3ISR
        PUBLIC     _SparkTimerErrISR
        EXTERN     _SparkTimer1ISRHandler
        EXTERN     _SparkTimer2ISRHandler
        EXTERN     _SparkTimer3ISRHandler
        EXTERN     _SparkTimerErrISRHandler
        EXTERN     _OSTCBCur
        EXTERN     _OSIntExit
        EXTERN     _OSIntNesting

        SECTION    __DEFAULT_CODE_SECTION__:CODE:NOROOT(2)
        
        
;********************************************************************************************************
;                                                sparkTimer1ISR()
;********************************************************************************************************
_SparkTimer1ISR:
        OS_CTX_SAVE                         ; save processor registers on the stack

        mov.l   #_OSIntNesting, r1          ; Increment OSIntNesting
        mov.b   @r1, r0
        extu.b  r0, r0
        add     #1, r0
        mov.b   r0, @r1                     ; If OSIntNesting == 1 save the current stack pointer
        tst     #1, r0                      ; onto the current task's stack
        bt      _SparkTimer1ISR1

        mov.l   #_OSTCBCur, r1              ; Save current task's SP into its TCB
        mov.l   @r1, r0
        mov.l   r15, @r0
        
_SparkTimer1ISR1:        
        mov.l   #_SparkTimer1ISRHandler, r0
        jsr     @r0                         ; call SparkTimer1ISRHandler()
        nop

        OS_CTX_RESTORE                      ; restore all processor registers from stack

        rte
        nop

;********************************************************************************************************
;                                                sparkTimer2ISR()
;********************************************************************************************************
_SparkTimer2ISR:
        OS_CTX_SAVE                         ; save processor registers on the stack

        mov.l   #_OSIntNesting, r1          ; Increment OSIntNesting
        mov.b   @r1, r0
        extu.b  r0, r0
        add     #1, r0
        mov.b   r0, @r1                     ; If OSIntNesting == 1 save the current stack pointer
        tst     #1, r0                      ; onto the current task's stack
        bt      _SparkTimer2ISR1

        mov.l   #_OSTCBCur, r1              ; Save current task's SP into its TCB
        mov.l   @r1, r0
        mov.l   r15, @r0
        
_SparkTimer2ISR1:        
        mov.l   #_SparkTimer2ISRHandler, r0
        jsr     @r0                         ; call SparkTimer2ISRHandler()
        nop

        OS_CTX_RESTORE                      ; restore all processor registers from stack

        rte
        nop
        
;********************************************************************************************************
;                                                sparkTimer3ISR()
;********************************************************************************************************
_SparkTimer3ISR:
        OS_CTX_SAVE                         ; save processor registers on the stack

        mov.l   #_OSIntNesting, r1          ; Increment OSIntNesting
        mov.b   @r1, r0
        extu.b  r0, r0
        add     #1, r0
        mov.b   r0, @r1                     ; If OSIntNesting == 1 save the current stack pointer
        tst     #1, r0                      ; onto the current task's stack
        bt      _SparkTimer3ISR1

        mov.l   #_OSTCBCur, r1              ; Save current task's SP into its TCB
        mov.l   @r1, r0
        mov.l   r15, @r0
        
_SparkTimer3ISR1:        
        mov.l   #_SparkTimer3ISRHandler, r0
        jsr     @r0                         ; call SparkTimer3ISRHandler()
        nop

        OS_CTX_RESTORE                      ; restore all processor registers from stack

        rte
        nop

;********************************************************************************************************
;                                                sparkTimerErrISR()
;********************************************************************************************************
_SparkTimerErrISR:
        OS_CTX_SAVE                         ; save processor registers on the stack

        mov.l   #_OSIntNesting, r1          ; Increment OSIntNesting
        mov.b   @r1, r0
        extu.b  r0, r0
        add     #1, r0
        mov.b   r0, @r1                     ; If OSIntNesting == 1 save the current stack pointer
        tst     #1, r0                      ; onto the current task's stack
        bt      _SparkTimerErrISR1

        mov.l   #_OSTCBCur, r1              ; Save current task's SP into its TCB
        mov.l   @r1, r0
        mov.l   r15, @r0

_SparkTimerErrISR1:
        mov.l   #_SparkTimerErrISRHandler, r0
        jsr     @r0                         ; call SparkTimerErrISRHandler()
        nop
        
        mov.l   #_OSIntExit, r0
        jsr     @r0                         ; call OSIntExit()
        nop

        OS_CTX_RESTORE                      ; restore all processor registers from stack

        rte
        nop
        END